package main

import (
	"fmt"
	"github.com/Shopify/sarama"
	"log"
)

func main() {

	consumer, err := sarama.NewConsumer([]string{"ip:9092"}, nil)
	if err != nil {
		panic(err)
	}

	topics, err := consumer.Topics()
	if err != nil {
		panic(err)
	}
	fmt.Println("topics", topics)

	for _, t := range topics {
		partitions, err := consumer.Partitions(t)
		if err != nil {
			fmt.Println("Partitions", err)
			continue
		}
		fmt.Println("topics", t, "partitions", partitions)
	}

	consumePartition, err := consumer.ConsumePartition("hello", 0, 0)
	if err != nil {
		panic(err)
	}
	messageChan := consumePartition.Messages()
	for {
		message := <-messageChan
		log.Println("[message]", "topic:", message.Topic, "key:", string(message.Key), "value:", string(message.Value))
	}
}
